<template>
  <div>
    <div style="width: 100%;height: 100px;">
      <a-row :gutter="[16, 8]">
        <a-col :span="6">
          <!-- <a-space>
              <a-button icon="left" @click.stop="goPrev"/>
              <a-date-picker v-model:value="currentMonth" placeholder="选择日期" :allowClear="false" @change="onChangeDate"/>
              <a-button icon="right" @click.stop="goNext"/>
            </a-space> -->
          <span>开始时间区间：</span>
          <a-range-picker
            style="width: 280px"
            v-model="queryParam.startTimeRange"
            @change="onDateRangeChange($event, 'StartTime')"
            :ranges="dataRange"
          />
        </a-col>
        <!--          <a-col :span="4" >-->
        <!--            <a-form-model-item label="姓名" prop="realname">-->
        <!--              <a-input v-model="queryParam.realname" placeholder="请输入姓名" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <!--          <a-col :span="4" >-->
        <!--            <a-form-model-item label="工号" prop="workNo">-->
        <!--              <a-input v-model="queryParam.workNo" placeholder="请输入工号" />-->
        <!--            </a-form-model-item>-->
        <!--          </a-col>-->
        <a-col :span="6">
          <!-- <a-form-model-item label="品种" prop="variety">
              <j-dict-select-tag placeholder="请选择" v-model="queryParam.aproductType"
                                 dictCode="crm_product_type_rove,product_type,id"/>
            </a-form-model-item> -->
          <span>结束时间区间：</span>
          <a-range-picker
            style="width: 280px"
            v-model="queryParam.endTimeRange"
            @change="onDateRangeChange($event, 'EndTime')"
            :ranges="dataRange"
          />
        </a-col>
        <a-col :span="4"></a-col>
        <a-col :span="4"></a-col>
        <a-col :span="4">
          <span>车间：</span>
          <j-dict-select-tag
            placeholder="请选择车间"
            v-model="queryParam.workshop"
            dictCode="workshop"
            style="width: 180px"
          />
        </a-col>
      </a-row>
      <a-row :gutter="16" style="margin-top: 10px;">
        <a-col :span="24">
          <a-space style="float: right">
            <a-upload
              name="file"
              :showUploadList="false"
              :multiple="false"
              :headers="tokenHeader"
              :action="importExcelUrl"
              @change="handleImportExcel"
            >
              <a-button type="default" icon="import">导入</a-button>
            </a-upload>
            <a-button @click="handleExportXls('粗纱品种公定参数')" type="default" icon="export">导出报表</a-button>
            <a-button @click="handleSearch()" type="primary" style="width: 100%">
              搜索
            </a-button>
            <a-button @click="handleAdd" type="primary">新增公定参数</a-button>
            <a-button @click="batchDel" type="default">批量删除</a-button>
            <!--            <a-button @click="generateSalary()" type="primary" style="width: 100%">-->
            <!--              生成报表-->
            <!--            </a-button>-->
            <!--            <a-button @click="ExportLengthReport()" style="width: 100%">导出长度报表</a-button>-->
            <!--            <a-button @click="ExportReport()" style="width: 100%">导出报表</a-button>-->
          </a-space>
        </a-col>
      </a-row>
    </div>
    <div style="margin-top: 30px;">
      <a-table
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :columns="columns"
        rowKey="id"
        :data-source="dataSource"
        :scroll="{ x: 3000 }"
        :pagination="ipagination"
      >
        <!-- 操作 -->
        <a-space slot="action" slot-scope="text, record">
          <template>
            <a-button style="padding: 0px" type="link" icon="edit" @click="handleEdit(record)">编辑</a-button>
            <a-popconfirm title="确认要删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button style="color: red; padding: 0px" type="link" icon="delete">删除</a-button>
            </a-popconfirm>
          </template>
        </a-space>
      </a-table>
    </div>
    <cu-sha-p-z-g-d-c-s-modal
      ref="modalForm"
      @ok="modalFormOk"
      :plan-time="queryParam.planTime"
    ></cu-sha-p-z-g-d-c-s-modal>
  </div>
</template>

<script>
import { getGenerateSalaryDataBlowing } from '../../../api/customApi'
import { JeecgListMixin } from '../../../mixins/JeecgListMixin'
import CuShaPZGDCSModal from './modules/CuShaPZGDCSModal'
import moment from 'moment'

const path = '/crm_product_type_params_rove/crmProductTypeParamsRove'
export default {
  mixins: [JeecgListMixin],
  components: { CuShaPZGDCSModal },
  data() {
    return {
      currentMonth: moment(),
      time: undefined,
      name: '',
      jobId: '',
      riqi: null,
      workshop: undefined,
      variety: undefined,
      jobType: '',
      dataSource,
      columns,
      queryParam: {
        // planTime: moment().format('YYYY-MM-DD')
      },
      url: {
        list: path + '/list',
        delete: path + '/delete',
        deleteBatch: path + '/deleteBatch',
        importExcelUrl: path + '/importExcel',
        exportXlsUrl: '/crm_product_type_params_rove/crmProductTypeParamsRove/exportExcel'
      },
      dataRange: {
        当天: [moment().startOf('day'), moment()],
        昨天: [
          moment()
            .startOf('day')
            .subtract(1, 'days'),
          moment()
            .startOf('day')
            .subtract(1, 'days')
        ],
        本周: [
          moment()
            .startOf('weeks')
            .subtract(0, 'weeks'),
          moment()
        ],
        上周: [
          moment()
            .startOf('week')
            .subtract(1, 'weeks'),
          moment()
            .endOf('week')
            .subtract(1, 'weeks')
        ],
        本月: [
          moment()
            .startOf('months')
            .subtract(0, 'months'),
          moment()
        ],
        上月: [
          moment()
            .month(moment().month() - 1)
            .startOf('month'),
          moment()
            .month(moment().month() - 1)
            .endOf('month')
        ],
        本季度: [
          moment()
            .quarter(moment().quarter())
            .startOf('quarter'),
          moment()
        ],
        本年度: [
          moment()
            .startOf('year')
            .subtract(0, 'years'),
          moment()
        ]
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}${this.url.importExcelUrl}`
    }
  },
  methods: {
    goPrev() {
      var newMonth = moment(this.currentMonth).subtract(1, 'day')
      this.currentMonth = newMonth
      this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
      this.searchQuery()
    },
    goNext() {
      var newMonth = moment(this.currentMonth).add(1, 'day')
      this.currentMonth = newMonth
      this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
      this.searchQuery()
    },
    onChangeDate(date, dateString) {
      this.queryParam.planTime = dateString
      this.searchQuery()
    },
    changeObject() {},
    refresh() {
      this.searchQuery()
    },
    handleSearch() {
      this.searchQuery()
      this.visible = false
    },
    handleCancel() {
      this.visible = false
    },
    handleReset() {
      this.searchReset()
    },
    add() {
      this.visable1 = true
    },
    detail(record) {},
    onChangePage(e) {
      this.ipagination.current = e
      this.loadData()
    },
    generateSalary() {
      let query = {
        // planTime: this.queryParam.planTime
      }
      getGenerateSalaryDataBlowing(query).then(res => {
        if (res.success) {
          this.$message.success('生成成功')
          this.searchQuery()
        }
      })
    },

    whole() {},
    classA() {},
    classB() {},
    ExportLengthReport() {},
    ExportReport() {},
    search() {},

    handleChange(value) {
      console.log(`selected ${value}`)
    },

    onChange(date, dateString) {
      console.log(date, dateString)
    },
    onDateRangeChange(event, extraParam) {
      this.$set(this.queryParam, 'start' + extraParam, moment(event[0]).format('YYYY-MM-DD 00:00:00'))
      this.$set(this.queryParam, 'end' + extraParam, moment(event[1]).format('YYYY-MM-DD 23:59:59'))
    }
  }
}
const columns = [
  { align: 'center', title: '创建日期', width: 200, dataIndex: 'createTime', key: 'createTime', fixed: 'left' },
  { align: 'center', title: '公司', width: 220, dataIndex: 'company_dictText', key: 'company_dictText', fixed: 'left' },
  {
    align: 'center',
    title: '车间',
    width: 100,
    dataIndex: 'workshop_dictText',
    key: 'workshop_dictText',
    fixed: 'left'
  },
  {
    align: 'center',
    title: '工序',
    width: 100,
    dataIndex: 'workingProcedure_dictText',
    key: 'workingProcedure_dictText',
    fixed: 'left'
  },
  { align: 'center', title: '开始时间', width: 180, dataIndex: 'startTime', key: 'startTime' },
  { align: 'center', title: '结束时间', width: 180, dataIndex: 'endTime', key: 'endTime' },
  { align: 'center', title: '车号', dataIndex: 'deviceNo', key: 'deviceNo', width: 150 },
  { align: 'center', title: '机型', dataIndex: 'deviceModel', key: 'deviceModel', width: 150 },
  { align: 'center', title: '品种类型', width: 100, dataIndex: 'productCategory', key: 'productCategory' },
  { align: 'center', title: '品种', width: 150, dataIndex: 'productType_dictText', key: 'productType_dictText' },
  { align: 'center', title: '定长', width: 150, dataIndex: 'length', key: 'length' },
  { align: 'center', title: '定量', dataIndex: 'ration', key: 'ration', width: 150 },
  { align: 'center', title: '定量范围', dataIndex: 'rationRange', key: 'rationRange', width: 150 },
  { align: 'center', title: '线速度（m/min）', dataIndex: 'linearVelocity', key: 'linearVelocity', width: 150 },
  { align: 'center', title: '线速度范围', dataIndex: 'linearVelocityRange', key: 'linearVelocityRange', width: 150 },
  { align: 'center', title: '输出棉条桶规格', dataIndex: 'cottonBarrelSize', key: 'cottonBarrelSize', width: 150 },
  { align: 'center', title: '定额（12小时）', dataIndex: 'weight', key: 'weight', width: 150 },
  { align: 'center', title: '定台', dataIndex: 'fixedMachinesNum', key: 'fixedMachinesNum', width: 150 },
  { align: 'center', title: '单价系数', dataIndex: 'unitPriceCoefficient', key: 'unitPriceCoefficient', width: 150 },
  {
    align: 'center',
    title: '品种系数',
    dataIndex: 'productTypeCoefficient',
    key: 'productTypeCoefficient',
    width: 150
  },
  {
    align: 'center',
    title: '落纱单价（元/次）',
    dataIndex: 'doffProductionUnitPrice',
    key: 'doffProductionUnitPrice',
    width: 200
  },
  {
    align: 'center',
    title: '换桶单价（元/桶）',
    dataIndex: 'bucketChangeUnitPrice',
    key: 'bucketChangeUnitPrice',
    width: 200
  },
  {
    align: 'center',
    title: '清洁产量单价（百米/元）',
    dataIndex: 'cleanProductionUnitPrice',
    key: 'cleanProductionUnitPrice',
    width: 240
  },
  { align: 'center', title: '台位单价（台/元）', dataIndex: 'platformUnitPrice', key: 'platformUnitPrice', width: 200 },
  {
    align: 'center',
    title: '推粗纱-落纱单价（落/元）',
    dataIndex: 'pushDoffProductionUnitPrice',
    key: 'pushDoffProductionUnitPrice',
    width: 200
  },
  {
    align: 'center',
    title: '推粗纱-挂纱、收管单价',
    dataIndex: 'pushHangYarnUnitPrice',
    key: 'pushHangYarnUnitPrice',
    width: 200
  },
  { align: 'center', title: '锭数', dataIndex: 'ingots', key: 'ingots', width: 150 },
  { align: 'center', title: '粗纱-机台系数', dataIndex: 'machineCoefficient', key: 'machineCoefficient', width: 150 },
  { align: 'center', title: '滤层台数', dataIndex: 'filterLayerNum', key: 'filterLayerNum', width: 150 },
  {
    title: '操作',
    dataIndex: 'action',
    align: 'center',
    scopedSlots: { customRender: 'action' },
    fixed: 'right'
  }
]
const dataSource = [
  {
    column1: 1,
    column2: 1,
    column3: 1,
    column4: 1,
    column5: 1,
    column6: 1,
    column7: 1,
    column8: 1,
    column9: 1,
    column10: 1,
    column11: 1,
    column12: 1,
    column13: 1,
    column14: 1,
    column15: 1,
    column16: 1,
    column17: 1,
    column18: 1,
    column19: 1,
    column20: 1,
    column21: 1,
    column22: 1,
    column23: 1,
    column24: 1,
    column25: 1,
    column26: 1,
    column27: 1,
    column28: 1,
    column29: 1,
    column30: 1,
    column31: 1,
    column32: 1,
    column33: 1,
    column34: 1,
    column35: 1,
    column36: 1,
    column37: 1,
    column38: 1,
    column39: 1,
    column40: 1,
    column41: 1,
    column42: 1,
    column43: 1,
    column44: 1,
    column45: 1
  }
]
</script>

<style scoped></style>
